package com.caijinbang.study.lock;

import lombok.extern.slf4j.Slf4j;
import redis.clients.jedis.Jedis;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Redis分布式锁(非公平锁)
 * 同一个锁的lock,unlock过程使用一个Redis连接锁的并发性能与JedisPool的最大连接数有关系
 *
 * @author caijb
 * @version 1.0.0
 * @date 2018-06-06 8:31
 */
@Slf4j
public class RedisLock implements Lock {

    /**
     * 默认延迟时间
     */
    private static final int DEFAULT_ACQUIRY_RESOLUTION_MILLIS = 100;

    /**
     * redis锁前缀
     */
    private static final String REDIS_LOCK_KEY_PREFIX = "lock:";
    private Jedis jedis;
    private String lockKey;
    private String lockValue;
    private volatile boolean locked = false;
    //单体应用内线程锁
    private volatile Lock threadLock = new ReentrantLock();

    /**
     * 锁超时时间，用于设置redis的过期时间，
     * 防止线程在入锁以后，因为异常状态导致锁无法正常释放，其他线程无限的执行等待
     */
    private int expireMsecs = 10 * 1000;


    @Override
    public void lock() {

    }


    @Override
    public void lockInterruptibly() throws InterruptedException {

    }


    @Override
    public boolean tryLock() {
        return false;
    }


    @Override
    public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
        return false;
    }


    @Override
    public void unlock() {

    }


    @Override
    public Condition newCondition() {
        return null;
    }
}
